package com.example.rumen;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner; // 添加Spinner的导入
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MySpinnerActivity extends AppCompatActivity {

    private TextView spinner_txt;
    private Spinner spinner1; // 修改为Spinner类型，而不是View

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_spinner);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        spinner_txt = findViewById(R.id.textView_Spinner);
        spinner1 = (Spinner) findViewById(R.id.spinner1); // 添加类型转换
        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String school = parent.getItemAtPosition(position).toString();
                spinner_txt.setText(school);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // 可以在这里添加当没有选择时的处理逻辑
            }
        });
    }
}